package UILayer;
import java.util.Scanner;
import ControlLayer.*;

/**
 * Write a description of class MainMenuUI here.
 * 
 * @author (Gruppe 2) 
 * @version (a version number or a date)
 */
public class MainMenuUI
{
    //the reference to the ControlLayer
    private CustomerUI cusUI;
    private SaleUI saleUI;
    private ItemUI itemUI;

    public MainMenuUI()
    {
    	mainMenuStart();

    }

    public void mainMenuStart()
    {
        boolean exit = false;
        while (!exit)
        {
            int choice = writeMainMenu();
            if(choice == 1)
            {
                System.out.println("\f");
                startCustomer();
            }
            if(choice == 2)
            {
                System.out.println("\f");
                startSale();
            }
            if(choice == 3)
            {
                System.out.println("\f");
                startItem();
            }
            if(choice == 4)
            {
                end();
                exit = true;
            }
        }
    }

    private int writeMainMenu()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.println("\f *** MainMenu ***");
        System.out.println(" (1) Customers");
        System.out.println(" (2) Sales");
        System.out.println(" (3) Items");
        System.out.println(" (4) Close");
        System.out.print("\n Please choose: ");
        
        boolean done = false;
        int choice = 0;
        while(!done)
        {
            try
            {
                choice = keyboard.nextInt();
                done = true;
            }
            catch (Exception e)
            {
                System.out.println("You must enter a number - try again");
                String input = keyboard.nextLine();
            }
        }
        return choice;
    }
    
    private void startCustomer()
    {
        cusUI = new CustomerUI();
    }
    
    private void startSale()
    {
        saleUI = new SaleUI();
    }
    
    private void startItem()
    {
        itemUI = new ItemUI();
    }
    
    private void end()
    {
        System.out.println(" System is shutting down.");
    }
    
    public static void main(String[] args)
    {
    	new MainMenuUI();
    }
}
